<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[
        { name: 'box-base', title: '基础信息' },
        { name: 'box-order', title: '订单单位' },
        { name: 'box-reg', title: '注册证信息' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="cpPropRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息
            <span class="span-tip" >仅部分属性可以修改，其余由院内推送更新</span>
          </div>
          <customFormItem label="规格" name="materialSpec" :parent="_self" :form="form" />
          <customFormItem label="单价" name="price" :parent="_self" :form="form"   :type="constCommon.formItemType.inputNumber.name"  disabled/>
          <customFormItem
            label="单品单位"
            name="unit"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.unit(unitSelect)"
            disabled
          />

          <customFormItem label="编码格式"  disabled name="inputCodingType" :parent="_self" :form="form" :type="constCommon.formItemType.selectDict.name" :config="{dictType: constCommon.dictType.baseInputCodingType}"/>
          <customFormItem label="是否寄售" disabled name="isConsignment" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name" :config="{flagValueBoolean: false}"/>
          <customFormItem label="标签管理" disabled name="isOneThingOneYard" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"  :config="{flagValueBoolean: false}"/>
          <customFormItem label="ERP编码" disabled name="materialErpCode" :parent="_self" :form="form" help="不指定，则将与商品ERP编码一致"/>

          <div id="box-order" class="box-title">订单单位</div>
          <customFormItem
            label="订单单位"
            name="orderUnit"
            :parent="_self"
            :form="form"
            :readonly="true"
            :showSelectIcon="true"
            @focus="utilSelect.unit(orderUnitSelect)"
            help-bottom="采购订单使用的单位"
          />
          <customFormItem label="订单单位比率" name="orderQty" :parent="_self" :form="form"   :type="constCommon.formItemType.inputNumber.name"
                          help-bottom="即可以换算成多少个基本单位数量"/>

          <div id="box-reg" class="box-title">注册证信息</div>
          <customFormItem label="注册证号" name="certificateNo" :parent="_self" :form="form" width2x />
          <customFormItem label="注册证开始" name="certificateExpiredStartDate" :parent="_self" :form="form" :type="constCommon.formItemType.datePicker.name" />
          <customFormItem label="注册证截止" name="certificateExpiredDate" :parent="_self" :form="form" :type="constCommon.formItemType.datePicker.name" />
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  help: '商品管理-规格',
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
    unitSelect(row) {
      this.$set(this.form, 'unit', row.name)
    },

    orderUnitSelect(row) {
      this.$set(this.form, 'orderUnit', row.name)
    }
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        let spType = this.form.spType || []
        if (spType.includes(this.constCommon.busConst.matrTypeMatr)){
          this.$set(this.form, 'isConsumable', 1)
        }
        if (spType.includes(this.constCommon.busConst.matrTypeDrug)){
          this.$set(this.form, 'isDrug', 1)
        }
        if (spType.includes(this.constCommon.busConst.matrTypeRreagent)){
          this.$set(this.form, 'isReagent', 1)
        }
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
        if (this.propParent.cpFormNew) {
          this.$set(this.form, 'materialId', this.propInitData.id)
          this.$set(this.form, 'isConsignment', 0)
          this.$set(this.form, 'isOneThingOneYard', 0)
          this.$set(this.form, 'materialErpCode', this.propInitData.materialErpCode)
        }
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: { customAnchor },
  computed: {
    cpPropRules() {
      let rule = this.propRules || {}
      return rule
    }
  },
}
</script>
